#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2019 crane <crane@gosun>
#
# Distributed under terms of the MIT license.

"""

"""

def reverse_order(nums):
    cnt = 0
    l = len(nums)

    for first_idx in range(l-1):
        for second_idx in range(first_idx+1, l):
            if nums[second_idx] < nums[first_idx]:
                cnt += 1

    return cnt


def test():
    assert reverse_order([5, 4, 3, 2, 1]) == 10
    assert reverse_order([2, 4, 3, 1]) == 4

    # 可以看到, 当n > 10000时, 计算速度是比较慢的
    n = 10000
    # assert reverse_order(range(n)) == n*(n-1)//2
    assert reverse_order( range(n)) == 0
    print("0 end")

    assert reverse_order( list(range(n, 0, -1))) == n*(n-1)//2

def main():
    print("start main")
    test()

if __name__ == "__main__":
    main()
